package app.ui;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JFrame;

public class MainFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8924308466844158184L;

	protected GridBagConstraints constraints;

	protected MP3PlayerUi mp3PlayerUi;

	public MainFrame() {
		super();

		this.getContentPane().setLayout(new GridBagLayout());
		this.constraints = new GridBagConstraints();
		constraints.fill = GridBagConstraints.BOTH;
		constraints.weightx = 1;
		constraints.weighty = 1;

		setDefaultCloseOperation(EXIT_ON_CLOSE);
		initialize();
		
		doAddComponents();
	}

	private void doAddComponents() {
		this.mp3PlayerUi = new MP3PlayerUi(this);
		mp3PlayerUi.open();		
	}

	public void initialize() {
		setTitle("Main Frame");
		setMinimumSize(new Dimension(480, 320));
		setLocation(280, 120);
		
		setUndecorated(true);
	}

	@Override
	public Component add(Component comp) {
		if (comp instanceof AbsCommonPanel) {
			AbsCommonPanel mPanel = (AbsCommonPanel) comp;
			mPanel.makeThisAutoResize();
			this.getContentPane().add(comp, getConstraints());
			return comp;
		}

		return super.add(comp);
	}

	public GridBagConstraints getConstraints() {
		return constraints;
	}
}
